package com.jeff.huawei.practice;

import java.util.LinkedList;
import java.util.Queue;

//使用贪心算法 预测参议院的胜利者
public class Test4 {
    public static void main(String[] args) {
        String sentence = "RDDDDRDR";
        System.out.println(predictTheWinner(sentence));
    }

    public static String predictTheWinner(String sentence) {
        int len = sentence.length();
        Queue<String> queue = new LinkedList();
        for (int i = 0; i < len; i++) {
            queue.offer(sentence.substring(i, i + 1));
        }
        while (queue.size() != 1) {
            String first = queue.poll();
            String second = queue.poll();
            while (first.equals(second)) {
                second = queue.poll();
            }
            if (first.equals("R") && second.equals("D")) {
                queue.offer(first);
            }
            else if (first.equals("D") && second.equals("R")) {
                queue.offer(first);
            }
        }
        return queue.peek();
    }
}
